import java.lang.reflect.Array;

public class Empresses {
    int max=8;
    int[] arr=new int[max];
    int count=0;
    public static void main(String[] args) {
        Empresses empresses = new Empresses();
        empresses.check(0);
        System.out.println(empresses.count);
    }
    public void check(int n){
        if (n==max){
            count++;
            print();
            return;
        }
        for (int i = 0; i < max; i++) {
            arr[n]=i;
            if (judge(n)){
                check(n+1);
            }
        }
    }
    public boolean judge(int n){
        for (int i = 0; i < n; i++) {
            if (arr[n]==arr[i]||Math.abs(n-i)==Math.abs(arr[n]-arr[i])){
                return false;
            }
        }
        return true;
    }
    public void print(){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
}

